# -*- coding: utf-8 -*-

from tools.mysqlconn import NBAdb
from mysql_text import sql_create_tables
from spider_get.get_url import Geturl
from spider_get.get_player_data import Playerdata
import re
import time


class NBA:

    def __init__(self):
        """
        初始化一些参数
        """
        # 实例化获取球员链接的类
        self._instance_one = Geturl()
        # 实例化获取球员数据的类
        self._instance_two = Playerdata()
        # 实例化管理数据库的类
        self.one = NBAdb()

    def nba_database_init(self):
        """
        批量执行创建数据表的语句
        :return:
        """

        # 1
        self.one.create_table(sql_create_tables.player_brief_introduction)

        # 2
        self.one.create_table(sql_create_tables.player_season_average_data)

        # 3
        self.one.create_table(sql_create_tables.player_season_average_data_count)

        # 4
        self.one.create_table(sql_create_tables.player_season_total_data)

        # 5
        self.one.create_table(sql_create_tables.player_season_total_data_count)

        # 6
        self.one.create_table(sql_create_tables.player_season_best_data)

        # 7
        self.one.create_table(sql_create_tables.player_season_best_data_count)

        # 8
        self.one.create_table(sql_create_tables.player_season_advanced_data_base)

        # 9
        self.one.create_table(sql_create_tables.player_season_advanced_data_base_count)

        # 10
        self.one.create_table(sql_create_tables.player_season_advanced_data_shooting)

        # 11
        self.one.create_table(sql_create_tables.player_season_advanced_data_shooting_count)

        # 12
        self.one.create_table(sql_create_tables.player_playoff_average_data)

        # 13
        self.one.create_table(sql_create_tables.player_playoff_average_data_count)

        # 14
        self.one.create_table(sql_create_tables.player_playoff_total_data)

        # 15
        self.one.create_table(sql_create_tables.player_playoff_total_data_count)

        # 16
        self.one.create_table(sql_create_tables.player_playoff_best_data)

        # 17
        self.one.create_table(sql_create_tables.player_playoff_best_data_count)

        # 18
        self.one.create_table(sql_create_tables.player_playoff_advanced_data_base)

        # 19
        self.one.create_table(sql_create_tables.player_playoff_advanced_data_base_count)

        # 20
        self.one.create_table(sql_create_tables.player_playoff_advanced_data_shooting)

        # 21
        self.one.create_table(sql_create_tables.player_playoff_advanced_data_shooting_count)

        # 22
        self.one.create_table(sql_create_tables.player_allstar_base_data)

        # 23
        self.one.create_table(sql_create_tables.player_allstar_average_data)

        # 24
        self.one.create_table(sql_create_tables.player_allstar_total_data)

        # 25
        self.one.create_table(sql_create_tables.player_season_score_list)

        # 26
        self.one.create_table(sql_create_tables.player_season_backboard_list)

        # 27
        self.one.create_table(sql_create_tables.player_season_assist_list)

        # 28
        self.one.create_table(sql_create_tables.player_season_cap_list)

        # 29
        self.one.create_table(sql_create_tables.player_season_steal_list)

        # 30
        self.one.create_table(sql_create_tables.player_season_time_list)

        # 31
        self.one.create_table(sql_create_tables.player_season_field_goal_list)

        # 32
        self.one.create_table(sql_create_tables.player_season_shoot_frequency_list)

        # 33
        self.one.create_table(sql_create_tables.player_season_three_point_goal_list)

        # 34
        self.one.create_table(sql_create_tables.player_season_three_point_frequency_list)

        # 35
        self.one.create_table(sql_create_tables.player_season_free_throw_goal_list)

        # 36
        self.one.create_table(sql_create_tables.player_season_free_throw_frequency_list)

        # 37
        self.one.create_table(sql_create_tables.player_season_mistake_list)

        # 38
        self.one.create_table(sql_create_tables.player_season_fouls_list)

        # 39
        self.one.create_table(sql_create_tables.player_season_undefined_list)

        # 40
        self.one.create_table(sql_create_tables.player_playoff_score_list)

        # 41
        self.one.create_table(sql_create_tables.player_playoff_backboard_list)

        # 42
        self.one.create_table(sql_create_tables.player_playoff_assist_list)

        # 43
        self.one.create_table(sql_create_tables.player_playoff_cap_list)

        # 44
        self.one.create_table(sql_create_tables.player_playoff_steal_list)

        # 45
        self.one.create_table(sql_create_tables.player_playoff_time_list)

        # 46
        self.one.create_table(sql_create_tables.player_playoff_field_goal_list)

        # 47
        self.one.create_table(sql_create_tables.player_playoff_shoot_frequency_list)

        # 48
        self.one.create_table(sql_create_tables.player_playoff_three_point_goal_list)

        # 49
        self.one.create_table(sql_create_tables.player_playoff_three_point_frequency_list)

        # 50
        self.one.create_table(sql_create_tables.player_playoff_free_throw_goal_list)

        # 51
        self.one.create_table(sql_create_tables.player_playoff_free_throw_frequency_list)

        # 52
        self.one.create_table(sql_create_tables.player_playoff_mistake_list)

        # 53
        self.one.create_table(sql_create_tables.player_playoff_fouls_list)

        # 54
        self.one.create_table(sql_create_tables.player_playoff_undefined_list)

        # 55
        self.one.create_table(sql_create_tables.player_personal_honor)

        # 56
        self.one.create_table(sql_create_tables.player_salary_list)

        # 57
        self.one.create_table(sql_create_tables.player_salary_total_list)

        # 58
        self.one.create_table(sql_create_tables.player_similar_players)

        del self.one

    def get_data(self):
        """
        批量执行获取并存储数据的语句
        :return:
        """
        coach_list, player_list, player_season_list, player_playoff_list,\
            player_allstar_list, coach_name_dic, player_name_dic = self._instance_one.get_playerlist_link()

        # # 执行球员全明星数据的插入
        # for i in player_allstar_list:
        #     nums = re.findall(r'\d+', i)
        #     name = player_name_dic[nums[0]]
        #     self._instance_two.get_allstar_data(i, name)

        # # 执行球员常规赛数据的插入
        # for i in player_season_list:
        #     nums = re.findall(r'\d+', i)
        #     name = player_name_dic[nums[0]]
        #     self._instance_two.get_season_data(i, name)
        #     time.sleep(2)

        # # 执行球员季后赛数据的插入
        # for i in player_playoff_list:
        #     nums = re.findall(r'\d+', i)
        #     name = player_name_dic[nums[0]]
        #     self._instance_two.get_playoff_data(i, name)
        #     time.sleep(1)

        # # 执行球员其他35个数据表的数据插入
        # # nba_one = player_list.index('http://www.stat-nba.com/player/3696.html')
        # # nba_two = player_list.index('')
        # for i in player_list:
        #     nums = re.findall(r'\d+', i)
        #     name = player_name_dic[nums[0]]
        #     self._instance_two.get_playerlist_data(i, name)
        #     time.sleep(2)

    def run(self):
        """
        执行代码的函数
        :return:
        """
        # self.nba_database_init()
        # self.get_data()


if __name__ == '__main__':
    """
    执行程序
    """
    NBA().run()

